package zouran.service.impl;


import org.springframework.stereotype.Service;
import zouran.entity.sauver.Fource;
import zouran.entity.sauver.Goods;
import zouran.mapper.SauverMapper;
import zouran.service.SauverService;

import java.util.List;
import java.util.Map;

@Service
public class SauverServiceImpl implements SauverService {


    private final SauverMapper sauverMapper;

    public SauverServiceImpl(SauverMapper sauverMapper) {
        this.sauverMapper = sauverMapper;
    }

    @Override
    public List<Fource> getAllForce() {
        return sauverMapper.getallforce();
    }

    @Override
    public List<Goods> getAllGoods() {
        return sauverMapper.getallgoods();
    }

    @Override
    public List<Fource> getForceBylimit(Map<String, String> params) {
        int limit =  Integer.parseInt(params.get("limit"));
        int page = Integer.parseInt(params.get("page"));
        String cityvalue = params.get("cityvalue");

        int offset = (page-1)*limit;
        return sauverMapper.getforceByLimit(cityvalue,offset,limit);
    }

    @Override
    public Goods getPointgoodsBy(int id) {
        return sauverMapper.getPointGoodsByid(id);
    }

    @Override
    public List<Fource> getearthquakeScopeforce(Map<String,Double> centerPointscope) {

        double distincescope =centerPointscope.get("distince");
        double lontitude = centerPointscope.get("lontitude");
        double latitude = centerPointscope.get("latitude");

        double radians = Math.toRadians(latitude);

        double offsetlon = distincescope/1000/111/Math.cos(radians);
        double offsetlat = distincescope/1000/111;

        double lontitudescope1 = lontitude + offsetlon;
        double lontitudescope2 = lontitude - offsetlon;

        double latitudescope1 = latitude+offsetlat;
        double latitudescope2 = latitude-offsetlat;


        return sauverMapper.getscopeForce(lontitudescope1,lontitudescope2,latitudescope1,latitudescope2);
    }
}
